#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;

vector<vector<int>> merge(vector<vector<int>>& intervals) {
    sort(intervals.begin(), intervals.end());
    vector<vector<int>> ret;
    for (int i = 0; i < intervals.size(); i++)// 1,3  2,6  8,10  15,18
    {
        ret.push_back({ intervals[i][0], intervals[i][1] });
        if (i != intervals.size() - 1)
        {
            int j = i + 1;
            for (; j < intervals.size(); j++)
            {
                if (ret[ret.size() - 1][1] >= intervals[j][0]) ret[ret.size() - 1][1] = max(ret[ret.size() - 1][1], intervals[j][1]);
                else
                    break;
            }
            i = j - 1;
        }
    }
    return ret;
}

int main()
{
	//vector<vector<int>> vv;
	//vv.push_back({ 1, 2 });
	vector<vector<int>> intervals{ { 2,6 }, { 1,3 }, { 0,10 }, { 15,18 } };
	sort(intervals.begin(), intervals.end());
    vector<vector<int>> vv{ {1,3} ,{2,6},{8,10}, {15,18} };
    merge(vv);

	return 0;
}